﻿using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using CalculatorService;

namespace MySelfHosting
{
    public class Program
    {
        public static void Main(string[] args)
        {
            try
            {
                var calculatorHost = new ServiceHost(typeof (Calculator));
                calculatorHost.Open();

                Console.WriteLine("\nThe Calculator service is running and is listening on:");

                foreach (ServiceEndpoint endpoint in calculatorHost.Description.Endpoints)
                {
                    Console.WriteLine("{0} ({1})", endpoint.Address, endpoint.Binding.Name);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("An error has occured: {0}", e.Message);
            }

            Console.WriteLine("\nPress any key to stop the service.");
            Console.ReadKey();
        }
    }
}